Manages the processing of macros.
public class MacroProcessor<T>
Public Class MacroProcessor(Of T)
generic<typename T>
public ref class MacroProcessor
Type Parameters
T
Type of data passed to the macro substitution delegates.
Macros are defined as ${macro_name} in strings. This class looks for those tokens and calls the appropriate registered delegate to return a string. The MacroProcessor class has the following default macros when created:
Value | Meaning |
---|---|
date | Current date. |
random_string | Random string of specified link. |
random_date | Random date in the specified min/max date range. |
empty | Empty string. |
random_time | Random time offset from the specified time. |
replace(value) | Releases the tag with the specified value. |
This example adds two macros to the macro processor and process a string.
using Leadtools.Dicom.Common.Anonymization;
public void MacroProcessorSample()
{
MacroProcessor<object> processor = new MacroProcessor<object>();
//
// add two macros to the macro processor
//
processor.Macros.Add("current_date", new MacroSubstitutionDelegate<object>(CurrentDateMacro));
processor.Macros.Add("current_time", new MacroSubstitutionDelegate<object>(CurrentTimeMacro));
//
// Process a macro string
//
Console.WriteLine(processor.Process(processor, "${current_date} ==> ${current_time}"));
}
private string CurrentDateMacro(object userData, string name, params object[] parameters)
{
return DateTime.Now.ToShortDateString();
}
private string CurrentTimeMacro(object userData, string name, params object[] parameters)
{
return DateTime.Now.ToShortTimeString();
}
Imports Leadtools.Dicom.Common.Anonymization
Public Sub MacroProcessorSample()
Dim processor As New MacroProcessor(Of Object)()
'
' add two macros to the macro processor
'
processor.Macros.Add("current_date", New MacroSubstitutionDelegate(Of Object)(AddressOf CurrentDateMacro))
processor.Macros.Add("current_time", New MacroSubstitutionDelegate(Of Object)(AddressOf CurrentTimeMacro))
'
' Process a macro string
'
Console.WriteLine(processor.Process(processor, "${current_date} ==> ${current_time}"))
End Sub
Private Function CurrentDateMacro(ByVal userData As Object, ByVal name As String, ByVal ParamArray parameters As Object()) As String
Return DateTime.Now.ToShortDateString()
End Function
Private Function CurrentTimeMacro(ByVal userData As Object, ByVal name As String, ByVal ParamArray parameters As Object()) As String
Return DateTime.Now.ToShortTimeString()
End Function
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document